package com.twu.biblioteca;

/**
 * Created by theyes on 15/01/2014.
 */
public class MainMenu {

    private MockBookDataBase bookDB = new MockBookDataBase();
    private MockMovieDataBase movieDB = new MockMovieDataBase();

    private User currentUser;
    public MainMenu(User cUser) {
        currentUser = cUser;
    }


    public  void initialise() {

        printMainMenu();

        askUserForInput();
    }

    private void askUserForInput() {
        UserInputHandler userInputHandle = new UserInputHandler();

        int userChoice = userInputHandle.readInputInt();

        while (processUserChoice(userChoice))
        {
            printMainMenu();
            userChoice = userInputHandle.readInputInt();
        }


    }

    // menus
    private ViewBookListMenu listBookMenu;
    private ReturnABookMenu returnBook;
    private ViewMoviesMenu listMovieMenu;
    private ReturnMovieMenu returnMovie;

    public boolean processUserChoice(int option) {

                switch (option)
        {
            case 0:
                System.out.println("Exiting");
            return false;
            case 1:
                if(listBookMenu == null)
                    listBookMenu = new ViewBookListMenu(bookDB);

                listBookMenu.startMenu();
                return true;
            case 2:
                if(returnBook == null)
                    returnBook = new ReturnABookMenu(bookDB);
                returnBook.attemptReturnItem();
                return true;
            case 3:
                if(listMovieMenu == null)
                    listMovieMenu = new ViewMoviesMenu(movieDB);
                listMovieMenu.startMenu();
                return true;
            case 4:
                if(returnMovie == null)
                    returnMovie = new ReturnMovieMenu(movieDB);
                returnMovie.attemptReturnItem();
                return true;
            case 5:
                System.out.println(currentUser.toString());
                return true;

            default:
            System.out.print("Invalid input.  Please try again.");
            return true;

        }

    }

    private static void printMainMenu() {

        System.out.println("What would you like to do?");
        System.out.println("Please select an option:");
        System.out.println("0)Exit");
        System.out.println("1) View and Checkout Books.");
        System.out.println("2) Return a Book");
        System.out.println("3) View and Checkout Movies");
        System.out.println("4) Return a Movie");
        System.out.println("5) View user Info");

    }



}
